﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using Tesseract;

namespace CatEars3.Demo.Tesseract
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Bitmap enPic = new Bitmap("Eng.png");
                Bitmap chPic = new Bitmap("Chi.png");

                InteropDotNet.LibraryLoader.Instance.CustomSearchPath
                    = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TesseractOcr");
                //path可以是相对路径，也可以是绝对路径
                string path = AppDomain.CurrentDomain.BaseDirectory;
                //string path = "";
                //TesseractEngine会在path后面自动补上tessdata/特定语言.traineddata
                using (TesseractEngine engEngine = new TesseractEngine(path, "eng", EngineMode.Default))
                {
                    using (var enPage1 = engEngine.Process(enPic, PageSegMode.Auto))
                    {
                        Console.WriteLine("enPic : " + enPage1.GetText());
                        Console.WriteLine("--------------------------------------------------");
                    }
                    using (var enPage2 = engEngine.Process(chPic, PageSegMode.Auto))
                    {
                        Console.WriteLine("chPic : " + enPage2.GetText());
                        Console.WriteLine("--------------------------------------------------");
                    }
                }

                using (TesseractEngine chiEngine = new TesseractEngine(path, "chi_sim", EngineMode.Default))
                {
                    using (var enPage2 = chiEngine.Process(chPic, PageSegMode.Auto))
                    {
                        Console.WriteLine("chPic : " + enPage2.GetText());
                        Console.WriteLine("--------------------------------------------------");
                    }
                    using (var enPage1 = chiEngine.Process(enPic, PageSegMode.Auto))
                    {
                        Console.WriteLine("enPic : " + enPage1.GetText());
                        Console.WriteLine("--------------------------------------------------");
                    }
                }
            }
            catch (Exception exc)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(exc.Message);
            }
            finally
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine();
                Console.Write("Any key to exit !");
                Console.ReadKey();
            }
        }
    }
}
